package com.holy.experiment11.Controller;

import com.holy.experiment11.Student.Student;
import com.holy.experiment11.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/api/students")//定义url路径
public class StudentController {
    @Autowired//自动注入studentService
    private StudentService studentService;
    @GetMapping  //get
    public List<Student> getAllStudents() {
        return studentService.findAllStudents();

    }

    @PostMapping   //post
    public Student addStudent(@RequestBody Student student) {
        return studentService.createStudent(student);
    }

    @PutMapping
    public Student updateStudent(@PathVariable Long id ,@RequestBody Student student) {
        return studentService.updateStudent(id, student);
    }

    @DeleteMapping
    public void deleteStudent(@PathVariable Long id ) {
        studentService.deleteStudent(id);
    }
  //添加其他功能代码

}
